Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement SoundHasTimeElapsed #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

asiekierka
Copy link

@asiekierka asiekierka commented Jun 6, 2020

SoundUninstall could be implemented to send a "quit" signal to the ticking routine, but I'm not sure if it has to be.

Also removes some code with DOS-specific workarounds that is not necessary here.

Sound does not work, but ticking speeds should now accurately match the original ZZT (though there's an odd issue with it occasionally doing a few ticks in one go for me, and I wonder why that is).

@benhoyt
Copy link
Owner

benhoyt commented Jun 6, 2020

Hey @asiekierka, thanks for this! I like how you've simulated the sound timer "interrupt handler" with a Ticker running on a background goroutine. However, the problem with this is that there's no CPU sleep, so when you run the game with your PR it uses 100% CPU as it's now a busy loop -- presumably the DOS one had the same issue, but that didn't really matter in the DOS days. :-)

You can see this by going to Activity Monitor (I'm on macOS) when you're on the TOWN.ZZT title screen. In the previous code it uses ~3% CPU, with this PR it uses ~100%.

So I think it'll have to be some kind of "sleep till the next tick wake-up time" approach. Whether that's a literal time.Sleep() or a wait on a ticker channel or something, I'm not sure.

@asiekierka
Copy link
Author

That did not... occur to me, somehow! Sorry, sorry.

You could just wait for the next Ticker tick if SoundHasTimeElapsed is false, yes; as it's not going to return true unless that's the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants